<?php
class BlogModel extends Model{
 public $table='blog';
 // 获得所有栏目
 public function addBlog(){
 	// 如有上传图片的，要对图片进行缩略处理
 	if(!empty($_FILES['thumb']['name'])){
 		$upload=new upload;
 		$files=$upload->upload();
 		$_POST['thumb']=$files[0]['path'];
 	}
// 发表时间
 	$_POST['addtime']=time();
 	return $this->insert($_POST);
 }
// 修改博客
 public function editBlog(){
 // 有缩略图先处理上传文件
 	if(!empty($_FILES['thumb']['name'])){
 		// 如果有原图时，删除它
 		if(is_file($_POST['thumb'])){

 			unlink($_POST['thumb']);
 		}
 		$upload=new upload;
 		$files=$upload->upload();
 		$_POST['thumb']=$files[0]['path'];
 	}

    // 发表时间
    $_POST['addtime']=time();
    return $this->where("bid='{$_POST['bid']}'")->update($_POST);
 }
// 读取博客
 public function getAll(){
 	
 	$result=$this->query('select count(*) as c from blog');
 	$page=new page($result[0]['c'],2);
 	$pageStr=$page->show();
 	$limit=$page->limit();
 	$sql="select * from blog as b join category as c on b.cid=c.cid order by bid desc LIMIT {$limit}" ;
 	$blog=$this->query($sql);
 	
 	return array('blog'=>$blog,'page'=>$pageStr);
 }

}
?>